package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Orders;
import com.itheima.reggie.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    //提交订单 也就是保存订单
    @PostMapping("/order/submit")
    public ResultInfo save(@RequestBody Orders orders){
        ordersService.save(orders);
        return ResultInfo.success(null);
    }

    //查询订单
    @GetMapping("/order/userPage")
    public ResultInfo findAll(@RequestParam(value = "page" ,defaultValue = "1") Integer pageNum,
                              @RequestParam(defaultValue = "10") Integer pageSize
                              ){
        Page<Orders> page =  ordersService.findAll(pageNum,pageSize);
        return  ResultInfo.success(page);
    }
}
